<?php
session_start();
require_once('./functions.php');
$lang = checkLanguage();
require_once($lang.".php");
$lang_lib = $_LANG['index'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <!-- This is the login page. You are redirected here whenever you're not logged in. -->
	<head>
		<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
		<link type="text/css" rel="stylesheet" href="./graphics/style1.css" />
		<link type="text/css" rel="stylesheet" href="graphics/jquery-ui-1.8.9.custom.css" />
		<script type="text/javascript" src="js/a-hip_lib.js"></script>
		<script type="text/javascript" src="js/jquery-1.4.3.js"></script>
		<script type="text/javascript" src="js/jquery-ui-1.8.9.custom.min.js"></script>
		<script src="js/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>
		<script src="js/jquery.form.js" type="text/javascript"></script>
		<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="js/swfupload/swfupload.js"></script>
		<script type="text/javascript" src="js/jquery.swfupload.js"></script>
		

		<?php
			if (isset($_SESSION['download'])){
				echo "
					<script type=\"text/javascript\">
					$(document).ready(function(){
						location.href='".$_SESSION['download']."';
					});
					</script>";
					$_SESSION['download'] = null;
			}
		?>
		<title><?echo $lang_lib['title']?></title>
	</head>
	<body> <!-- TODO: Some finnish here. "kokosivu" means "wholepage". -->
		<div id="kokosivu">
		  <div id="username" class="column_set2">
		    <div class="column2">
		      <img src="graphics/logo.png" />
		    </div>
		    <div class="column2">
		      <p class="header">
			      <?php
				      if(isset($_SESSION['logged'])){
					      echo $lang_lib['logged'].$_SESSION['user']."<br /><br /><a id=\"logout\" href=\"?logout\">".$lang_lib['logout']."</a>";
				      }
				      else{
					      echo $lang_lib['not_logged'];
				      }
			      ?>
			    </p>
			  </div>
			</div>
			<!-- The Tabs are in these divs. TODO: Some finnish. "navigointipalkki" = "navigationbar". "valilehdet" = "tabs". -->
			<div id="navigointipalkki">
				<ul class="valilehdet">
					<li>
						<a href="?p=file_management"><?echo $lang_lib['file_management']?></a>
					</li>
					<li>
						<a href="?p=preferences"><?echo $lang_lib['setup']?></a>
					</li>
					<li>
						<a href="<?echo $_LANG['index']['user_manual_filename']?>" target="_blank"><?echo $_LANG['index']['user_manual']?></a>
					</li>
				</ul>
			</div>
			<!-- When logging in, all the required files are loaded here. TODO: Some finnish here. "runko" = "body". -->
			<div id="runko">
				<?php
					if(isset($_SESSION['logged'])) {
						if(isset($_GET['logout'])) {
						session_destroy();
						header("Location: ./index.php");
						}
					}
					if(isset($_GET['p']) && $_GET['p'] == "info") {
						include("./info.php");
					} else {
						if(!isset($_SESSION['logged'])) {
	 						if(isset($_GET['p'])) {
								$p = $_GET['p'];
								if($p == "register")
									include("./register.php");
								else if($p == "anonymous_login")
									include("./anonymous_login.php");
								else
									include("./login_site.php");
					    		}
							else
								include("./login_site.php");
					  	} else {
							if(isset($_GET['p'])) {
								$p = $_GET['p'];
								if($p == "file_management") {
									include("./file_management.php");
								} else if($p == "file_management2") {
									include("./file_management2.php");
								} else if($p == "edit"){
									include("edit.php");
								} else if($p == "edit2"){
									include("edit2.php");
								} else if($p == "preferences") {
									include("./preferences.php");
								} else if($p == "multiupload") {
									include("./multiupload.php");
								}
							} else {
								include("./file_management.php");
							}
						}
					}
				?>
			</div>
		</div>
	</body>
</html>
